package com.woniuxy.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.woniuxy.entity.MyhOrder;
import com.woniuxy.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @Author: 马宇航
 * @Todo: TODO
 * @DateTime: 25/03/07/星期五 11:48
 * @Component: 成都蜗牛学苑
 **/
@RestController
@RequestMapping("/order")
public class OrderController extends BaseController {
    @Autowired
    OrderService orderService;
    @PostMapping("/")
    public AjaxResult addOrder(@RequestBody MyhOrder order) {
        if (order == null) {
            return AjaxResult.error("订单信息不能为空");
        }
        if (order.getId() == null){
            //新增
            orderService.save(order);
        }else {
            //修改
            orderService.updateById(order);
        }
        return AjaxResult.success();
    }
    @GetMapping("/{startPage}/{pageSize}")
    public TableDataInfo getOrderList(@PathVariable int startPage,@PathVariable int pageSize) {
        startPage();
        List<MyhOrder> lists = orderService.findAll();
        return getDataTable(lists);
    }

    @DeleteMapping("/{ids}")
    public AjaxResult deleteOrder(@PathVariable Long[] ids) {
        boolean b = orderService.removeByIds(Arrays.asList(ids));
        return AjaxResult.success();
    }
}
